﻿
/// <reference path="jquery-1.3.2.min-vsdoc.js" />


function newstoggle(ID) {
    $('#NewsTextID' + ID).slideToggle(500);
};

$(function() {

    $('.News_feed').click(function() {

        $('.News_feed').css("border-color", "#ccc")

        $(this).css("border-color", "#EB8231")

    });


    $('.News_feed').hover(function() {

        $(this).css("border-color", "#EB8231")

    }, function() {

        $('.News_feed').css("border-color", "#ccc")
    });

    function DisplayFeed(url) {

        $('#Feed_List .News_feed').remove();
        $('#Feed_Header h2').hide();

        $('<div id="LoadingImg"><img src="/Content/Images/Loading.gif" /></div>').appendTo('#Feed_List');

        $.ajax({
            type: "POST",
            url: "/News/GetFeed",
            data: "url=" + url,
            dataType: "json",
            success: function(news) {

                $('#Feed_Header h2').show();
                $('#Feed_Header h2').html(news.RssTitle);

                var html = "";
                var i;
                for (i = 0; i < news.AntalNews; i++) {


                    /*
                    html += '<div class="News_feed"><div class="NewsHeadFont" id="NewsHeadID' + news.NewsID[i] + '"><span>' + news.NewsDate[i] + '</span><h2><a href="' + news.NewsLink[i] + '" title="Link til ' + news.Newstitle[i] + '">' + news.Newstitle[i] + '</a></h2><em>Af: Daniel Toft</em></div><div class="NewsText" id="NewsTextID' + news.NewsID[i] + '">' + news.NewsSummary[i] + '</div></div>'
                    */

                    $('#News_feed_Clone .News_feed:first').clone(true).appendTo('#Feed_List').children('.News_feed').slideDown(1000);


                    $('#Feed_List .News_feed:last .NewsHeadFont span').html(news.NewsDate[i]);
                    $('#Feed_List .News_feed:last .NewsHeadFont h2 a').html(news.Newstitle[i]);
                    $('#Feed_List .News_feed:last .NewsHeadFont h2 a').attr("href", news.NewsLink[i]).attr("title", 'Link til "' + news.Newstitle[i] + '"');



                    $('#Feed_List .News_feed:last .NewsText').html(news.NewsSummary[i]);




                }





                /*


                          $('#Feed_List').prepend(html).children('.News_feed').hide().fadeIn(1000);
                */
                $('#LoadingImg').remove('#LoadingImg');

            }

        });

    };

    /* $('#Menu_Macbay').click(function() {
    DisplayFeed('http://macbay.dk/feed');
    });

              $('#Menu_Comon').click(function() {

              });

              $('#Menu_Mediamac').click(function() {
    DisplayFeed('http://mediamac.comon.dk/rss.php');
    });
    $('#Menu_MacNationen').click(function() {
    DisplayFeed('http://macnation.newz.dk/rss/');
    });
    $('#Menu_Macnyt').click(function() {
    DisplayFeed('http://www.macnyt.dk/rss/');
    });
    $('#Menu_C4D').click(function() {
    DisplayFeed('http://c4d.dk/component/option,com_bca-rss-syndicator/feed_id,9/lang,da/');
    });
    $('#Menu_Newz').click(function() {
    DisplayFeed('http://newz.dk/rss/');
    });
    */
    function GeetFeedURL(ID) {

        var url;

        switch (ID) {
            case 'Menu_Macbay':
                url = 'http://macbay.dk/';
                break;
            case 'Menu_Mediamac':
                url = 'http://mediamac.comon.dk/rss.php';
                break;
            case 'Menu_MacNationen':
                url = 'http://macnation.newz.dk/rss/';
                break;
            case 'Menu_Macnyt':
                url = 'http://www.macnyt.dk/rss/';
                break;
            case 'Menu_C4D':
                url = 'http://c4d.dk/component/option,com_bca-rss-syndicator/feed_id,9/lang,da/';
                break;
            case 'Menu_Newz':
                url = 'http://newz.dk/rss/';
                break;
            default:
                url = 'http://macbay.dk/feed';
        }

        return url;
    };


    $('.FeedText').click(function() {

        var ID = $(this).attr('id');



        DisplayFeed(GeetFeedURL(ID));
    });


    $('.News_Feed_Navi').hover(function() {


        $(this).children('div.imgbtnStyle').show();

    }, function() {
        $(this).children('div.imgbtnStyle').hide();

    });


    $('div .imgbtnStyle').click(function() {
        $(this).parent('.News_Feed_Navi').remove();
    });

    $('#AddFeed img').click(function() {
        $('#AddFeedContent').slideDown(1000);
        $('#AddFeed img').fadeOut(1000);

    });

    $('#AddFeedContent input').click(function() {

    });
    $('#AddFeedContent img').click(function() {
        var Name = $('#txtFeedName').val();
        var IDname = 'Menu_' + Name;

        $(this).parent('.News_Feed_Navi').remove();
        /*
        var NewFeed = '<div class="News_Feed_Navi"><div class="FeedText" id="' + IDname + '">' + Name + '</div><div class="imgbtnStyle"><img src="/Content/Images/cancel_48.png" alt="DeleteFeed" title="Delete Feed" /></div></div>';

                  $('#Feeds:last').append(NewFeed).children('.News_Feed_Navi:last').hide().slideDown(200);
                  
        */



        $('.News_Feed_Navi:first').clone(true).insertAfter('.News_Feed_Navi:last').slideDown(1000);

        $('.News_Feed_Navi:last .FeedText').html(Name).attr('id', IDname);






        $('#AddFeedContent').fadeOut(500, function() {

            $('#AddFeed img').fadeIn(500);
        });

    });


});